package com.ptswitch.material.service.impl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hxzon.util.MD5;
import com.ptswitch.material.dao.UserDao;
import com.ptswitch.material.model.Uzer;
import com.ptswitch.material.service.UserService;
import com.ptswitch.material.util.DateUtils;

@Service("userSer")
public class UserServiceImpl extends LoggerService implements UserService {
	@Resource
	private UserDao userDao;

	public long countAll() {
		return userDao.countAll();
	}

	public long countLike(String like) {
		return userDao.countLike(like);
	}
	
	public void delete(String id){
		userDao.delete(id);
	}

	public void delete(Uzer model) {
		userDao.delete(model);
	}

	public void deleteAll() {
		userDao.deleteAll();
	}

	public void deleteAll(List<Uzer> models) {

	}

	public Uzer get(String id) {
		return userDao.get(id);
	}

	public Uzer getByName(String username) {
		return userDao.getByName(username);
	}

	public Uzer getByNameAndPassword(String username, String password, boolean md5) {
		if (md5) {
			password = MD5.toMD5(username + password);
		}
		return userDao.getByNameAndPassword(username, password);
	}

	public boolean isAdmin(String username) {
		Uzer user = getByName(username);
		return user != null && user.getAdminGrade() == 0;
	}

	public boolean isAdmins(String username) {
		Uzer user = getByName(username);
		return user != null && user.getAdminGrade() <= 1;
	}

	public List getAll() {
		return userDao.getAll();
	}

	public List getAll(long first, long size) {
		return userDao.getAll(first, size);
	}

	public List getLike(String like, long first, long size) {
		return userDao.getLike(like, first, size);
	}

	public void save(Uzer model) {
		model.setCreateTime(DateUtils.format(new Date()));
		userDao.save(model);
	}

	public void saveAll(List<Uzer> models) {

	}

	public boolean existName(String username) {
		return (userDao.getByName(username) != null);
	}

	public long countLike(Uzer model) {
		// TODO Auto-generated method stub
		return 0;
	}

	public List<Uzer> getLike(Uzer model, long first, long size) {
		// TODO Auto-generated method stub
		return null;
	}

	public String valid(Uzer model) {
		return null;
	}
}
